package com.baizhi.service;

import com.baizhi.dao.UserDAO;
import com.baizhi.entity.User;
import com.baizhi.util.MybatisUtil;

import java.util.List;
import java.util.UUID;

public class UserServiceImpl implements UserService {
    @Override
    public void register(User user) {
        try {
            UserDAO userDAO = MybatisUtil.getSqlSession().getMapper(UserDAO.class);
            String id = UUID.randomUUID().toString();
            user.setId(id);
            System.out.println("+++++++++++++++++++++");
            userDAO.save(user);
            MybatisUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            MybatisUtil.rollback();
        }
    }

    @Override
    public List<User> showAll() {
        UserDAO userDAO = MybatisUtil.getSqlSession().getMapper(UserDAO.class);
        List<User> users = userDAO.selectAll();
        MybatisUtil.close();
        return users;
    }
}
